Step 2: Open the Checkout URL in WebView
Once you have a checkout URL from your backend, use WePaySDK.openCheckoutUrl() to present the checkout screen.
Usage​
import WePaySDK
class ViewController: UIViewController {
func openWePayCheckout(checkoutUrl: String) {
WePaySDK.openCheckoutUrl(
from: self,
checkoutUrl: checkoutUrl
)
}
}
What Happens Automatically​
Calling WePaySDK.openCheckoutUrl() will:
- Create a
WebViewPaymentViewController - Embed it in a
UINavigationController - Present it full screen (
modalPresentationStyle = .fullScreen) - Watch URL redirects for
/successor/error - Show an alert and dismiss the screen automatically
SwiftUI Support​
If you are using SwiftUI, wrap the call in a UIViewControllerRepresentable or trigger it from a UIHostingController:
import SwiftUI
import WePaySDK
struct CheckoutButton: View {
let checkoutUrl: String
@State private var showCheckout = false
var body: some View {
Button("Pay Now") {
showCheckout = true
}
.fullScreenCover(isPresented: $showCheckout) {
WePayCheckoutView(checkoutUrl: checkoutUrl)
}
}
}
struct WePayCheckoutView: UIViewControllerRepresentable {
let checkoutUrl: String
func makeUIViewController(context: Context) -> UINavigationController {
let webVC = WebViewPaymentViewController(checkoutUrl: checkoutUrl)
let nav = UINavigationController(rootViewController: webVC)
nav.modalPresentationStyle = .fullScreen
return nav
}
func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
}
Next Step​
See Step 3 — Advanced Usage if you prefer to use WebViewPaymentViewController directly, or skip to Configuration for Info.plist settings.